package com.liu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * @Author: 刘浩然
 * @Date: 2020/3/25 14:16
 */
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    @Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Bean
@Override
protected UserDetailsService userDetailsService(){
        return super.userDetailsService();
}

@Override
protected  void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("admin")
                .password("$123456")
                .roles("admin")
                .and()
                .withUser("sang")
                .password("$123456")
                .roles("user");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
     http.antMatcher("/oauth/**").authorizeRequests()
     .antMatchers("/oauth/**").permitAll()
     .and().csrf().disable();
}





}
